package com.example.mdm4

import android.app.Application
import android.content.Context
import com.alibaba.android.arouter.launcher.ARouter
import com.example.mdm4.delegate.MyAppRequestListener
import com.example.mdm4.delegate.MyComponentDelegate
import com.example.mdm4.delegate.MyPhoneInfoDelegate
import com.example.mdm4.delegate.MyTaskDescriptionDelegate
import com.lody.virtual.client.core.VirtualCore
import com.lody.virtual.client.core.VirtualCore.VirtualInitializer
import com.lody.virtual.client.stub.VASettings

class App:Application() {

    override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
        VASettings.ENABLE_IO_REDIRECT = true
        VASettings.ENABLE_INNER_SHORTCUT = false
        try {
            VirtualCore.get().startup(base)
        } catch (e: Throwable) {
            e.printStackTrace()
        }
    }
    override fun onCreate() {
        super.onCreate()
        ARouter.init(this)
        ARouter.openLog()
        ARouter.openDebug()

        val virtualCore = VirtualCore.get()
        virtualCore.initialize(object : VirtualInitializer() {
            override fun onMainProcess() {
//                Once.initialise(this@VApp)
                /*Builder()
                    .withLogEnabled(true)
                    .withListener {}
                    .build(this@VApp, "48RJJP7ZCZZBB6KMMWW5")*/
            }

            override fun onVirtualProcess() {
                //listener components
                virtualCore.componentDelegate = MyComponentDelegate()
                //fake phone imei,macAddress,BluetoothAddress
                virtualCore.phoneInfoDelegate = MyPhoneInfoDelegate()
                //fake task description's icon and title
                virtualCore.taskDescriptionDelegate = MyTaskDescriptionDelegate()
            }

            override fun onServerProcess() {
                virtualCore.setAppRequestListener(MyAppRequestListener(this@App))
                virtualCore.addVisibleOutsidePackage("com.tencent.mobileqq")
                virtualCore.addVisibleOutsidePackage("com.tencent.mobileqqi")
                virtualCore.addVisibleOutsidePackage("com.tencent.minihd.qq")
                virtualCore.addVisibleOutsidePackage("com.tencent.qqlite")
                virtualCore.addVisibleOutsidePackage("com.facebook.katana")
                virtualCore.addVisibleOutsidePackage("com.whatsapp")
                virtualCore.addVisibleOutsidePackage("com.tencent.mm")
                virtualCore.addVisibleOutsidePackage("com.immomo.momo")
            }
        })
    }
}